cc.Class({
    extends: cc.Component,

    properties: {
        label: cc.Label,
        showTime: 2,
    },

    // use this for initialization
    onLoad: function () {
        // 单例设置为常驻节点
        cc.game.addPersistRootNode(this.node);
        // 赋值给全局方法
        GameToast.showMessage = (msg) => this.show(msg);
        // 默认不显示tips
        this.node.active = false;
        // 不传递透明度
        this.node.cascadeOpacity = false;
        // 设置位置
        this.getComponent(cc.Widget).enabled = true;

        cc.logEx('messageTips初始化');
    },

    show: function(str) {
        this.node.active = true;
        this.label.string = str;
        if (this._show) this.unschedule(this._show);
        this._show = () => {
            this.node.active = false;
        };
        this.scheduleOnce(this._show, this.showTime);
    }
});